using System.Collections;
using System.Html;
using System.Runtime.CompilerServices;
using Nsb.Classes;
using jQueryApi;

namespace MinionsEdit.Classes
{
    [IgnoreNamespace]
    public class TinyPopup : Actor
    {
        private const string Css = @"
        .TinyPopup {
            position: absolute;
            width: 200px;
            background-color: rgba(255,255,255,.65);
            border: 1px solid black;
            -moz-border-radius: 4px;
            -webkit-border-radius: 4px;
            border-radius: 4px;
        }
        ";

        static TinyPopup()
        {
            AddStyle(Css);
        }

        protected TinyPopup()
        {
            Hider(true);
            Element = jQuery.FromHtml("<div/>")
                .AddClass("TinyPopup AboveHider WhiteGradiant")
                .CSS(new Dictionary("position", "absolute"))
                .AppendTo(jQuery.FromElement(Document.Body))
                ;
            jQuery.Document.Bind("keydown.TinyPopup", KeysEv);
        }

        protected virtual void Destroy(jQueryEvent e)
        {
            Element.Remove();
            Hider(false);
            jQuery.Document.Unbind(".TinyPopup");
        }

        protected virtual void KeysEv(jQueryEvent e)
        {
            if (e.Which == 27)
                CancelEv(e);
        }

        protected virtual void CancelEv(jQueryEvent e)
        {
            Inform.Debug("TinyPopup.CancelEv()");
            Destroy(e);
        }
    }
}